<!--
 * @Author: your name
 * @Date: 2020-11-23 13:32:05
 * @LastEditTime: 2021-09-24 15:02:41
 * @LastEditors: jerry.zzy
 * @Description: In User Settings Edit
 * @FilePath: \cang-chu-guan-li-xi-tong\src\views\chukuguanli\XiaoShouChuKuLieBiao.vue
-->
<template>
  <a-card :bordered="false" title>
    <!-- 搜索 -->
    <a-form v-bind="layout">
      <!-- 单据号 -->
      <a-row>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="单据号">
            <a-select
              v-model="searchForm.document"
              showSearch
              style="width: 100%"
            >
              <a-select-option
                v-for="(item, index) in OrderList"
                :key="index"
                :value="item"
              >
                {{ item }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <!-- 仓库名称 -->
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="仓库名称">
            <a-select
              v-model="searchForm.depotName"
              @change="changeDepotId"
              showSearch
              style="width: 100%"
            >
              <a-select-option
                v-for="item in storageList"
                :key="item.depotId"
                :value="item.depotNo + '|' + item.depotName"
                >{{ item.depotNo }} {{ item.depotName }}</a-select-option
              >
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="审核状态" ref="sort" prop="sort">
            <a-select v-model="searchForm.auditMark" @change="getCheckTag">
              <a-select-option value="1">已审核</a-select-option>
              <a-select-option value="2">未审核</a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <!-- 制单日期 -->
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="制单日期" ref="sort" prop="sort">
            <a-range-picker
              style="width: 100%"
              v-model="searchForm.sort"
              @change="getRangeTime"
            />
          </a-form-model-item>
        </a-col>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="制单人">
            <a-select
              v-model="searchForm.prepared"
              style="width: 100%"
              showSearch
            >
              <a-select-option
                v-for="(item, index) in PreparedyList"
                :key="index"
                :value="item.id"
              >
                {{ item.id_dictText }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="同步状态">
            <a-select v-model="searchForm.isSynchronized" style="width: 100%">
              <a-select-option
                v-for="item in isSynchronizedList"
                :value="item"
                :key="item"
              >
                {{ item }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-item label="源单号">
            <a-input
              v-model="searchForm.sourceNumber"
              style="width: 100%"
              placeholder="请输入源单号"
            />
          </a-form-item>
        </a-col>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="是否出库">
            <a-select v-model="searchForm.whetherInOutMark">
              <a-select-option value="1">是</a-select-option>
              <a-select-option value="0">否</a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col
          style="margin-left: -65px"
          :xl="12"
          :lg="12"
          :md="12"
          :sm="24"
          :xs="24"
        >
          <a-form-model-item label="存货名称">
            <a-select
              v-model="searchForm.inventoryName"
              @change="getInventoryInfo"
              showSearch
              style="width: 100%"
              @search="handleInventoryInfoSearch"
            >
              <a-select-option
                v-for="item in inventoryList"
                :key="item.inventoryId"
                :value="
                  item.inventoryId +
                  '|' +
                  item.inventoryNo +
                  '|' +
                  item.inventoryName +
                  '|' +
                  item.standardModel +
                  '|' +
                  item.unit
                "
              >
                {{ item.inventoryNo }} {{ item.inventoryName }}
                {{ item.standardModel }} {{ item.unit }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form>
    <a-form v-bind="layout2">
      <a-row>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24"></a-col>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24"></a-col>
        <a-col
          :xl="8"
          :lg="8"
          :md="12"
          :sm="24"
          :xs="24"
          :style="{ textAlign: 'right' }"
        >
          <a-button type="primary" @click="Search()">查询</a-button>
          <a-button style="margin-left: 8px" @click="Reset()">重置</a-button>
          <a-button style="margin-left: 8px" @click="exportToExcel"
            >导出</a-button
          >
        </a-col>
      </a-row>
    </a-form>
    <!-- 搜索下的表格 -->
    <a-table
      :columns="columns"
      :data-source="dataSource"
      :pagination="pagination"
      @change="handleTableChange"
      :scroll="{ x: 1900, y: 670 }"
      size="small"
      style="margin-top: 20px"
    >
      <span slot="document" slot-scope="text, record">
        <a @click="RouterJump(record)">
          {{ text }}
        </a>
      </span>
      <span slot="seeRemarkShelf" slot-scope="text, records">
        <a @click="showRemarkShelf(records)">点击查看</a>
      </span>
      <span slot="shelfNo" slot-scope="text, records">
        <a @click="showShelfNo(records)">点击查看</a>
      </span>

      <template slot="options" slot-scope="text, record">
        <a-popconfirm
          ok-text="确定"
          cancel-text="取消"
          @confirm="Delete(record.id)"
          v-if="record.auditMark != 1"
        >
          <template slot="title">
            <p>确定删除？</p>
          </template>
          <a type="danger"> 删除 </a>
        </a-popconfirm>
      </template>
    </a-table>
    <a-modal
      title="货架"
      :visible="visible1"
      width="40%"
      :labelCol="{ span: 8 }"
      :WapperCol="{ span: 5 }"
      @cancel="handleCancel1"
    >
      {{ this.remarkShelf }}
    </a-modal>
    <a-modal
      title="出库货架"
      :visible="visible2"
      width="40%"
      :labelCol="{ span: 8 }"
      :WapperCol="{ span: 5 }"
      @cancel="handleCancel2"
      @ok="addgoods_Ok"
    >
      {{ this.shelfNo }}
    </a-modal>
  </a-card>
</template>
<script>
// import * as XLSX from "xlsx";

// import { openDownloadDialog, sheet2blob } from "@/utils/export.js";

import { CommonAjax } from "@/services/modules/common";
const comHttp = new CommonAjax(); // 公用接口

import { mapState, mapGetters } from "vuex"; //

const columns = [
  {
    title: "序号",
    dataIndex: "key",
    key: "key",
    align: "center",
    width: "50px",
  },
  {
    title: "单据日期",
    dataIndex: "documentDate",
    key: "documentDate",
    align: "center",
    width: "100px",
  },
  {
    title: "审核标志",
    dataIndex: "auditMark_dictText",
    key: "auditMark_dictText",
    align: "center",
    width: "80px",
  },
  // {
  //   title: "记账标志",
  //   dataIndex: "bookkeepingMark_dictText",
  //   key: "bookkeepingMark_dictText",
  //   align: "center",
  // },
  {
    title: "同步标志",
    dataIndex: "isSynchronized",
    key: "isSynchronized",
    align: "center",
    width: "80px",
  },
  {
    title: "是否反审核",
    dataIndex: "isAntiAudit",
    key: "isAntiAudit",
    align: "center",
    width: "100px",
  },
  {
    title: "单据号",
    dataIndex: "document",
    key: "document",
    align: "center",
    width: "110px",
    scopedSlots: { customRender: "document" },
  },
  // {
  //   title: "仓库编码",
  //   dataIndex: "depotNo",
  //   key: "depotNo",
  //   align: "center",
  //   width: "110px",
  // },
  {
    title: "仓库名称",
    dataIndex: "depotId_dictText",
    key: "depotId_dictText",
    align: "center",
    width: "110px",
  },
  {
    title: "客户",
    dataIndex: "clientId_dictText",
    key: "clientId_dictText",
    align: "center",
    width: "120px",
  },
  // {
  //   title: "业务员",
  //   dataIndex: "yewuyuan",
  //   key: "yewuyuan",
  //   align: "center",
  // },
  // {
  //   title: "所属单位",
  //   dataIndex: "storageUnit_dictText",
  //   key: "storageUnit_dictText",
  //   align: "center",
  // },
  {
    title: "存货编码",
    dataIndex: "inventoryNo",
    key: "inventoryNo",
    align: "center",
    width: "110px",
  },
  {
    title: "存货名称",
    dataIndex: "inventoryId_dictText",
    key: "inventoryId_dictText",
    align: "center",
    width: "110px",
  },
  {
    title: "规格型号",
    dataIndex: "standardModel",
    key: "standardModel",
    align: "center",
    width: "80px",
  },
  {
    title: "单位",
    dataIndex: "unit",
    key: "unit",
    align: "center",
    width: "80px",
  },
  {
    title: "辅助单位",
    dataIndex: "auxiliaryUnit",
    key: "auxiliaryUnit",
    align: "center",
    width: "80px",
  },
  {
    title: "数量",
    dataIndex: "quantity",
    key: "quantity",
    align: "center",
    width: "80px",
  },
  // {
  //   title: "单价",
  //   dataIndex: "danjia",
  //   key: "danjia",
  //   align: "center",
  // },

  // {
  //   title: "金额",
  //   dataIndex: "money",
  //   key: "money",
  //   align: "center",
  // },
  {
    title: "批次号",
    dataIndex: "batchNumber",
    key: "batchNumber",
    align: "center",
    width: "100px",
  },
  {
    title: "是否赠品",
    dataIndex: "giveaway_dictText",
    key: "giveaway_dictText",
    align: "center",
    width: "80px",
  },
  {
    title: "制单人",
    dataIndex: "singleProducer_dictText",
    key: "singleProducer_dictText",
    align: "center",
    width: "80px",
  },
  {
    title: "负责人",
    dataIndex: "responsiblePerson_dictText",
    key: "responsiblePerson_dictText",
    align: "center",
    width: "80px",
  },
  {
    title: "审核人",
    dataIndex: "inspector_dictText",
    key: "inspector_dictText",
    align: "center",
    width: "80px",
  },
  {
    title: "源单号",
    dataIndex: "sourceNumber",
    key: "sourceNumber",
    align: "center",
    width: "80px",
  },

  {
    title: "备注",
    dataIndex: "remark",
    key: "remark",
    align: "center",
    width: "80px",
  },
  {
    title: "货架",
    dataIndex: "seeRemarkShelf",
    key: "seeRemarkShelf",
    align: "center",
    width: "80px",
    scopedSlots: { customRender: "seeRemarkShelf" },
  },
  {
    title: "是否出库",
    dataIndex: "whetherInOutMark",
    key: "whetherInOutMark",
    align: "center",
    width: "80px",
  },
  {
    title: "出库货架",
    dataIndex: "shelfNo",
    key: "shelfNo",
    align: "center",
    width: "80px",
    scopedSlots: { customRender: "shelfNo" },
  },
  {
    title: "出库时间",
    dataIndex: "inoutTime",
    key: "inoutTime",
    align: "center",
    width: "110px",
    scopedSlots: { customRender: "inoutTime" },
  },
  {
    title: "操作",
    dataIndex: "options",
    key: "options",
    align: "center",
    width: "80px",
    scopedSlots: { customRender: "options" },
  },
];

const rowSelection = {
  onChange: (selectedRowKeys, selectedRows) => {
    console.log(
      `selectedRowKeys: ${selectedRowKeys}`,
      "selectedRows: ",
      selectedRows
    );
  },
  onSelect: (record, selected, selectedRows) => {
    console.log(record, selected, selectedRows);
  },
  onSelectAll: (selected, selectedRows, changeRows) => {
    console.log(selected, selectedRows, changeRows);
  },
};

export default {
  data() {
    return {
      isSynchronizedList: ["已同步", "未同步"],
      // ---------- 分页使用 -------------
      pagination: {
        total: 0,
        current: 1,
        pageSize: 10, //每页中显示10条数据
        pageSizeOptions: ["10", "20", "30"], // 每页中显示的数据
        showTotal: (total) => `共有${total}条数据`, //分页中显示总的数据
        showSizeChanger: true, // 显示页面条数改变
        showQuickJumper: true, // 显示快速跳转
      },
      queryParam: {
        //查询参数
        page: 1, //第几页
        size: 10, //每页中显示数据的条数
        hosName: "",
        hosCode: "",
        province: "",
        city: "",
      },
      // 搜索栏布局
      layout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 18 },
      },
      layout2: {
        labelCol: { span: 6 },
        wrapperCol: { span: 8 },
      },
      // 搜索列表
      searchForm: {
        whetherInOutMark: "", //是否出库
        sourceNumber: "", //源单号
        document: "", // 单据号
        depotId: "", // 仓库id
        inventoryId: "", // 存货Id
        startTime: "",
        endTime: "",
        storageUnitId: "", // 所属单位Id
        deptId: "", //销售部门id
        prepared: "",
        isSynchronized: "", //同步状态

        depotName: undefined, // 仓库名称
        inventoryName: undefined, // 存货名称

        storageUnit: undefined, // 所属单位名称

        dept: undefined, // 销售部门
        auditMark: "",

        sort: null, // 时间段
      },

      // 生产材料出库列表
      columns,
      dataSource: [],
      rowSelection,
      visible1: false, //修改弹窗
      visible2: false, //修改弹窗

      // 列表
      OrderList: [], // 订单列表，返回所有的销售出库单
      storageList: [], // 仓库
      goodsList: [], // 存货
      saleDepartmentList: [], // 销售部门
      ALLOrderList: [], // 所有的订单列表,存储订单单号
      inventoryList: [],
      PreparedyList: [], //制单人列表

      checkTag: "N",
      remarkShelf: "",
      shelfNo: "",

      queryPathCache: "", // 查询缓存
    };
  },

  watch: {
    $route(to) {
      if (to.path == "/SaleOutputList") {
        this.getOutStorageList();
      }
    },
  },
  computed: {
    // 获取本地数据
    ...mapState("user", { currUser: "info", currPost: "position" }),
    ...mapGetters({
      getDepsInfo: "user/getDepsInfo",
    }),
    // ...mapState("setting", ["isMobile"]),
  },

  mounted() {
    this.getOutStorageList(); //
    this.getStorageList(); // 仓库列表
    this.getSaleDepartmentList(); // 获取销售部门
    this.getOrderList(); // 获取订单列表
    this.getPreparedyList(); //获取制单人列表
  },
  methods: {
    // 获取制单人列表
    getPreparedyList() {
      comHttp.getPreparedyList().then((res) => {
        var pattern = new RegExp("[\u4E00-\u9FA5]+");

        console.log("获取制单人列表:::::", res);
        let data = res.result.list.filter((item) => {
          if (pattern.test(item.id)) {
            console.log(item.id);
          } else if (item.id == null) {
            console.log(item.id);
          } else {
            return item;
          }
        });
        console.log(data);
        this.PreparedyList = data;
      });
    },
    showRemarkShelf(records) {
      //查看货架按钮
      this.visible1 = !this.visible1;
      console.log(records);
      this.remarkShelf = records.remarkShelf;
    },
    showShelfNo(records) {
      this.shelfNo = [];
      //查看货架按钮
      this.visible2 = !this.visible2;
      console.log(records);

      comHttp.getqueryShelves("?inoutDetailId=" + records.twoId).then((res) => {
        this.shelfNo = res.result.map((item) => {
          return item.shelfNo;
        });
        this.shelfNo = this.shelfNo.length == 0 ? "未查询到数据" : this.shelfNo;
      });
    },
    handleCancel1() {
      // 修查看货架按弹窗取消
      this.visible1 = false;
    },
    handleCancel2() {
      // 修查看货架按弹窗取消
      this.visible2 = false;
    },
    // 是否审核
    getCheckTag() {
      let queryPath = this.getQueryPath();
      this.getOutStorageList(queryPath);
    },
    //延迟
    debounce(value, wait) {
      if (this.timeout) clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        this.onfunc(value);
      }, wait);
    },
    // handleInventoryInfoSearch(value) {
    //   this.debounce(value, 2000);
    // },
    // 仓库物品模糊查询,解决卡顿的问题
    async handleInventoryInfoSearch(value) {
      //模糊查询
      var goodsList_invname = [];
      var goodsList_invspec = [];
      this.inventoryList = [];
      if (value.match(/^[ ]*$/)) {
        console.log("字符串为空或全空格");
      } else {
        this.inventoryList = [];
        let queryPath = "?name=" + value;
        if (value == "" || value == null) {
          this.inventoryList = [];
        } else {
          this.inventoryList = [];
          await comHttp
            .getSearchInventoryInformationFile(queryPath)
            .then((res) => {
              console.log("res", res.result);
              for (let i = 0; i < res.result.length; i++) {
                let data = {
                  inventoryId: res.result[i].pkInvbasdoc, // 存货 id
                  inventoryName: res.result[i].invname,
                  inventoryNo: res.result[i].invcode,
                  standardModel: res.result[i].invspec,
                  unit: res.result[i].measname,
                };
                goodsList_invname.push(data);
              }
            });
          let queryInventoryBySpec = "?invspec=" + value;
          //规格型号模糊查询
          await comHttp
            .getqueryInventoryBySpec(queryInventoryBySpec)
            .then((res) => {
              console.log("结果规格型号模糊查询", res);

              for (let i = 0; i < res.result.list.length; i++) {
                let data = {
                  inventoryId: res.result.list[i].pkInvbasdoc, // 存货 id
                  inventoryNo: res.result.list[i].invcode, //存货编码
                  inventoryName: res.result.list[i].invname, //存货名称
                  standardModel: res.result.list[i].invspec, //规格型号
                  unit: res.result.list[i].measname, //单位
                };
                goodsList_invspec.push(data);
              }
            });
          //todo 合并去重函数
          await this.mergeArray(goodsList_invname, goodsList_invspec);
        }
      }
    },
    //todo 合并去重函数
    mergeArray(arr1, arr2) {
      let arrs = [...arr1, ...arr2];

      //根据inventoryId去重
      let map = new Map();
      for (let item of arrs) {
        if (!map.has(item.inventoryId)) {
          map.set(item.inventoryId, item);
        }
      }
      this.inventoryList = [...map.values()];
    },
    // 获取销售出库列表  默认查询路径为第一页,
    getOutStorageList() {
      let _query = this.queryPathCache;

      if (!_query) {
        _query =
          "?pageNo=" +
          this.queryParam.page +
          "&pageSize=" +
          this.queryParam.size +
          "&inOutCategoryIdentification=3" +
          "&inOutIdentification=2";
      }
      comHttp.getInOrOutStorageOrderAndGoodsList(_query).then((res) => {
        this.dataSource = [];
        this.ALLOrderList = [];
        console.log("获取仓库列表", res);
        const pagination = { ...this.pagination };
        pagination.total = res.result.total;
        pagination.pageSize = res.result.size;
        this.pagination = pagination;

        for (let i = 0; i < res.result.records.length; i++) {
          let data = {
            twoId: res.result.records[i].twoId,
            id: res.result.records[i].id,
            key: (res.result.current - 1) * 10 + i + 1,
            documentDate: res.result.records[i].documentDate, // 单据日期
            auditMark_dictText: res.result.records[i].auditMark_dictText, // 审核标志
            auditMark: res.result.records[i].auditMark, // 审核标志
            isOutBound: "否",
            bookkeepingMark: res.result.records[i].bookkeepingMark, // 记账标志
            bookkeepingMark_dictText:
              res.result.records[i].bookkeepingMark_dictText, // 记账标志
            isSynchronized: res.result.records[i].isSynchronized, // 审核标志
            isAntiAudit: res.result.records[i].isAntiAudit, // 反审核标志
            depotId_dictText: res.result.records[i].storname, // 仓库名称
            depotNo: res.result.records[i].storcode, // 仓库名称

            clientId_dictText: res.result.records[i].clientId_dictText, // 客户
            // 业务员
            storageUnit_dictText: res.result.records[i].storageUnit_dictText, // 所属单位

            inventoryNo: res.result.records[i].invcode, // 存货编码
            inventoryId_dictText: res.result.records[i].invname, // 存货名称
            standardModel: res.result.records[i].invspec, // 规格型号

            unit: res.result.records[i].measname, // 单位
            auxiliaryUnit: res.result.records[i].auxiliaryUnit_dictText, // 辅助单位
            quantity: res.result.records[i].quantity, // 数量
            // unitPrice: res.result.records[i].unitPrice, // 单价
            // money: res.result.records[i].unitPrice,// 金额
            batchNumber: res.result.records[i].batchNumber, // 批次号
            giveaway_dictText: res.result.records[i].giveaway_dictText, // 是否赠品
            singleProducer_dictText:
              res.result.records[i].singleProducer_dictText, // 制单人
            singleProducer: res.result.records[i].singleProducer, // 制单人

            responsiblePerson_dictText:
              res.result.records[i].responsiblePerson_dictText, // 负责人
            inspector_dictText: res.result.records[i].inspector_dictText, // 审核人
            inspector: res.result.records[i].inspector, // 审核人Id
            // 记账标志
            sourceNumber: res.result.records[i].sourceNumber, // 源单号

            sendReceiveType: res.result.records[i].sendReceiveType, // 收发类别
            sendReceiveType_dictText:
              res.result.records[i].sendReceiveType_dictText, // 收发类别

            remark: res.result.records[i].remarks, // 备注
            remarkShelf: res.result.records[i].remarkShelf, //货架
            shelfNo: res.result.records[i].shelfNo, //实际出入库货架d,
            inoutTime: res.result.records[i].inoutTime, //实际出入库时间
            whetherInOutMark:
              res.result.records[i].whetherInOutMark == 0 ? "否" : "是", //实际是否出入库标志
          };
          // console.log(
          //   "",
          //   this.ALLOrderList.indexOf(res.result.records[i].document)
          // );
          // 如果所有订单列表中包含了该订单
          if (this.ALLOrderList.indexOf(res.result.records[i].document) > -1) {
            console.log("没有重复");
            this.dataSource.push(data);
          } else {
            console.log("已经重复");
            this.ALLOrderList.push(res.result.records[i].document);
            data[`document`] = res.result.records[i].document;
            this.dataSource.push(data);
          }
        }
      });
    },
    // 获取全局查询条件
    getQueryPath() {
      console.log(this.searchForm);
      let queryPath =
        "?pageNo=" +
        this.queryParam.page +
        "&pageSize=" +
        this.queryParam.size +
        "&inOutCategoryIdentification=3" +
        "&inOutIdentification=2" +
        "&auditMark=" +
        this.searchForm.auditMark + // 是否审核
        "&document=" +
        this.searchForm.document + // 单据号
        "&depotId=" +
        this.searchForm.depotId + // 仓库名称
        "&inventoryId=" +
        this.searchForm.inventoryId + // 存货名称
        "&beginDate=" +
        this.searchForm.startTime + //
        "&endDate=" +
        this.searchForm.endTime + //
        "&storage_unit=" +
        this.searchForm.storageUnitId + //所属单位
        "&deptId=" +
        this.searchForm.deptId +
        "&singleProducer=" + //制单人
        this.searchForm.prepared +
        "&isSynchronized=" + //审核状态
        this.searchForm.isSynchronized +
        "&sourceNumber=" + //源单号
        this.searchForm.sourceNumber +
        "&whetherInOutMark=" + //是否入库
        this.searchForm.whetherInOutMark;

      this.queryPathCache = queryPath;

      return queryPath; // 返回的查询条件
    },

    // 重置当前页码及页码参数
    resetPagination() {
      this.pagination = {
        total: 0,
        current: 1,
        pageSize: 10, //每页中显示10条数据
        pageSizeOptions: ["10", "20", "30"], // 每页中显示的数据
        showTotal: (total) => `共有${total}条数据`, //分页中显示总的数据
        showSizeChanger: true, // 显示页面条数改变
        showQuickJumper: true, // 显示快速跳转
      };
      //查询参数
      this.queryParam = {
        page: 1, //第几页
        size: 10, //每页中显示数据的条数
        hosName: "",
        hosCode: "",
        province: "",
        city: "",
      };
    },

    // 分页函数
    handleTableChange(pagination) {
      this.pagination.current = pagination.current;
      this.pagination.pageSize = pagination.pageSize;
      this.queryParam.page = pagination.current;
      this.queryParam.size = pagination.pageSize;
      let queryPath = this.getQueryPath();
      this.getOutStorageList(queryPath);
    },

    // 查询
    Search() {
      let queryPath = this.getQueryPath();
      this.getOutStorageList(queryPath);
      console.log("查询条件为:::", queryPath);
    },

    // -------------- 完成 ---------------------
    // 路由跳转函数
    RouterJump(record) {
      console.log(record);

      // 审核人
      if (record.inspector == this.$store.state.user.info.id) {
        console.log("这是审核人,能审核,能提交");
        this.$router.push({
          path: "SaleOutputDetail",
          query: {
            Id: record.id,
          },
        });
      }
      // 制单人，能修改
      else if (record.singleProducer == this.$store.state.user.info.id) {
        console.log("这是制单人,能修改");
        // 如果未审核，则能修改，审核过了则不能修改
        if (record.auditMark == 2) {
          this.$router.push({
            path: "SaleOut",
            query: {
              Id: record.id,
            },
          });
        } else {
          // 审核过了,不能修改
          this.$router.push({
            path: "SaleOutputDetail",
            query: {
              Id: record.id,
            },
          });
        }
        // 其余人员
      } else {
        console.log("这是其余人员,仅能查看，不能审核和提交");
        this.$router.push({
          path: "SaleOutputDetail",
          query: {
            Id: record.id,
          },
        });
      }
    },
    // 获取仓库列表
    getStorageList() {
      // 获取仓库名称
      this.storageList = [];
      comHttp.getStorageName().then((res) => {
        for (let i = 0; i < res.result.length; i++) {
          let data = {
            depotName: res.result[i].storname, //仓库名称
            depotNo: res.result[i].storcode, //仓库编码
            depotId: res.result[i].pkStordoc, //id
          };
          this.storageList.push(data);
        }
      });
    },
    // 获取仓库编码
    changeDepotId(value, option) {
      this.searchForm.depotId = option.key;
    },

    // 获取存货id
    getInventoryInfo(value, option) {
      this.searchForm.inventoryId = option.key;
      console.log("存货id::::", this.searchForm.inventoryId);
    },
    // 获取所属单位id
    changestorageUnitId(value, option) {
      this.searchForm.storageUnitId = option.key;
      console.log("所属单位id::::", this.searchForm.storageUnitId);
    },

    // 获取销售部门列表
    getSaleDepartmentList() {
      this.saleDepartmentList = [];
      comHttp.getSaleDepartment().then((res) => {
        console.log(res);
        for (let i = 0; i < res.result.length; i++) {
          let data = {
            value: res.result[i].value,
            title: res.result[i].title,
          };
          this.saleDepartmentList.push(data);
        }
      });
    },
    //获取部门id
    changedeptId(value, option) {
      this.searchForm.deptId = option.key;
      console.log("部门id::::", this.searchForm.deptId);
    },
    // 获取时间段
    getRangeTime(date, dateString) {
      this.searchForm.startTime = dateString[0];
      this.searchForm.endTime = dateString[1];
    },
    // 重置查询条件
    Reset() {
      this.searchForm = {
        whetherInOutMark: "", //是否出库
        sourceNumber: "", //源单号
        isSynchronized: "", //同步状态
        document: "", // 单据号
        documentId: "", // 单据号id
        depotId: "", // 仓库id
        depotName: undefined, // 仓库名称
        inventoryName: undefined, // 存货名称
        inventoryId: "", // 存货Id
        storageUnit: undefined, // 所属单位名称
        storageUnitId: "", // 所属单位Id
        dept: undefined, // 销售部门
        deptId: "", //销售部门id
        prepared: "",
        sort: null, // 时间段
        startTime: "",
        endTime: "",
        auditMark: "",
      };
      this.queryPathCache = "";

      this.resetPagination();
      this.getOutStorageList();
    },

    // 删除
    Delete(id) {
      comHttp.deleteInOrOutStorageOrderAndGoods("?id=" + id).then((res) => {
        if (res && res.code === 200) {
          this.$message.success("删除成功");
          this.getOutStorageList();
        } else {
          this.$message.error("删除失败");
        }
      });
    },

    // 根据仓库Id获取物品信息
    getGoodSInfo(id) {
      this.goodsList = [];
      comHttp.getInventoryInformationByStorageId("?id=" + id).then((res) => {
        console.log("获取存货信息:::::", res);
        for (let i = 0; i < res.result.length; i++) {
          let data = {
            inventoryId: res.result[i].id, // 存货 id
            inventoryName: res.result[i].inventoryName,
            inventoryNo: res.result[i].inventoryNo,
          };
          this.goodsList.push(data);
        }
      });
    },
    // 获取单据号列表
    getOrderList() {
      let queryPath = "?string=XSCK-";
      comHttp.getOrderList(queryPath).then((res) => {
        console.log("获取销售订单列表:::::", res);
        for (let i = 0; i < res.result.length; i++) {
          this.OrderList.push(res.result[i]);
        }
      });
    },
    addgoods_Ok() {
      this.visible2 = false;
    },

    // 导出列表
    exportToExcel() {
      this.queryPath =
        "?inOutCategoryIdentification=3" +
        "&inOutIdentification=2" +
        "&auditMark=" +
        this.searchForm.auditMark + // 是否审核
        "&document=" +
        this.searchForm.document + // 单据号
        "&depotId=" +
        this.searchForm.depotId + // 仓库名称
        "&inventoryId=" +
        this.searchForm.inventoryId + // 存货名称
        "&beginDate=" +
        this.searchForm.startTime + //
        "&endDate=" +
        this.searchForm.endTime + //
        "&storage_unit=" +
        this.searchForm.storageUnitId + //所属单位
        "&deptId=" +
        this.searchForm.deptId +
        "&singleProducer=" + //制单人
        this.searchForm.prepared +
        "&isSynchronized=" + //审核状态
        this.searchForm.isSynchronized +
        "&sourceNumber=" + //源单号
        this.searchForm.sourceNumber +
        "&whetherInOutMark=" + //是否入库
        this.searchForm.whetherInOutMark;
      comHttp
        .exportSaleOut(this.queryPath)
        .then((response) => {
          //如果后端返回的result是进过Blob处理的，直接 window.URL.createObjectURL(result)，如果没有，就需要先实例化new Blod处理之后再window.URL.createObjectURL(blob)。
          //文件名 文件保存对话框中的默认显示
          let fileName = "销售出库单.xls";
          let data = response.data;
          if (!data) {
            return;
          }
          console.log(response);
          //构造a标签 通过a标签来下载
          let url = window.URL.createObjectURL(new Blob([data]));
          let a = document.createElement("a");
          a.style.display = "none";
          a.href = url;
          //此处的download是a标签的内容，固定写法，不是后台api接口
          a.setAttribute("download", fileName);
          document.body.appendChild(a);
          //点击下载
          a.click();
          // 下载完成移除元素
          document.body.removeChild(a);
          // 释放掉blob对象
          window.URL.revokeObjectURL(url);
        });
    },
  },
};
</script>
<style scoped lang="less">
.avatar-uploader > .ant-upload {
  width: 160px;
  height: 160px;
}
.ant-upload-select-picture-card i {
  font-size: 32px;
  color: #999;
}

.ant-upload-select-picture-card .ant-upload-text {
  margin-top: 8px;
  color: #666;
}
textarea {
  border: 0;
  border-radius: 5px;
  border: 1px #d9d9d9 solid;
  width: 100%;
  height: 100px;
  padding: 10px;
  resize: none;
}
#feng_kong_cuo_shi_1 {
  width: 700px;
}
</style>
